package com.itcast.donkey.activity;

import android.app.Activity;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;

import com.itcast.donkey.R;
import com.itcast.donkey.adapters.TravelHeadAdapter;
import com.itcast.donkey.fragments.InHeadLikeFragment;
import com.itcast.donkey.fragments.InHeadTravelFragment;
import com.itcast.donkey.fragments.OffLineBrowerAttackFragment;
import com.itcast.donkey.fragments.OffLineBrowerTravelFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lanouhn on 16/9/8.
 */
public class OffLineBrowerActivity extends AppCompatActivity {
    private TabLayout tabLayout;
    private ViewPager viewPager;
    private List<String> tabName = new ArrayList<>();
    private List<Fragment> fragments = new ArrayList<>();
    private TravelHeadAdapter adapter;
    private ImageView logo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_off_line_brower);
        initView();
        initEvent();
        initData();
    }

    private void initView() {
        tabLayout = (TabLayout) findViewById(R.id.tabLayout);
        viewPager = (ViewPager) findViewById(R.id.viewPager);
        logo = (ImageView) findViewById(R.id.logo);

    }

    private void initEvent() {
        logo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

    }

    private void initData() {
        tabName.add("游记");
        tabName.add("攻略");
        OffLineBrowerTravelFragment travelFragment = new OffLineBrowerTravelFragment();
        OffLineBrowerAttackFragment attackFragment = new OffLineBrowerAttackFragment();

        fragments.add(travelFragment);
        fragments.add(attackFragment);
        //实例化适配器
        adapter = new TravelHeadAdapter(getSupportFragmentManager(), tabName, fragments);
        //设置适配器
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);
    }
}
